clear all
global system "linux"

if "${system}" == "linux" {
	global code "/"
	global s "/"
}

run "${code}${s}_set-path.do"
cd "${code}/DataImport"


*** Security level data

use "${embsRaw}/embs-sec.dta", clear

// duplicates cusip_id and secmnem_id
sort cusip_id 
by cusip_id: keep if _n == _N

sort secmnem_id issue_id
by secmnem_id: keep if _n == _N

// clean dates
foreach x of varlist issue_date mat_date {
	replace `x' = substr(`x', 1, 10)
	gen temp = date(`x', "YMD")
	drop `x'
	rename temp `x'
	format `x' %td
}
*drop if year(issue_date) < 1990
compress

// trim blank space
foreach x of varlist embs_product embs_productsuptype secmnem_id tbaeligcode_id {
	replace `x' = trim(`x')
}



save "${cached}/embs-sec-cleaned.dta", replace
save "${embsCleaned}/embs-sec-cleaned.dta", replace
